import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false
//引入vuex
import Vuex from 'vuex'
Vue.use(Vuex)

// 挂载vuex
const store = new Vuex.Store(
  {
    //开始严格模式
    strict: true,

    state: {

      sum: 0
    },
    //state只能通过mutations来改变
    mutations: {
      setSum(state,data) {
        state.sum+=data
      }
    },
    actions:{
      asyncSetSum(store,data){
        setTimeout(()=>{
          store.commit('setSum',data)
        },2000)
      }
    }
  }
)

new Vue({
  store,
  render: h => h(App),
}).$mount('#app')
